#include<bits/stdc++.h>
using namespace std;
int n,m,L,V,d[100010],v[100010],a[100010],cnt[100010],l[100010],r[100010],p[100010],vis[100010];
vector<int> tt[100010];
bool judge(int u)
{	if(u==0)
		return 1;
	for(int i=1;i<=m;i++)
		if(!vis[i])
		{	int flag=1;
			for(int j=0;j<tt[i].size();j++)
				if(cnt[tt[i][j]]==1)
				{	flag=0;
					break;
				}
			if(flag)
			{	vis[i]=1;
				for(int j=0;j<tt[i].size();j++)
					cnt[tt[i][j]]--;
				int t=judge(u-1);
				for(int j=0;j<tt[i].size();j++)
					cnt[tt[i][j]]++;
				vis[i]=0;
				if(t)
					return t;
			}
		}
	return 0;
}
int main()
{   freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--)
    {   scanf("%d %d %d %d",&n,&m,&L,&V);
        memset(d,0,sizeof(d));
        memset(v,0,sizeof(v));
        memset(a,0,sizeof(a));
        memset(p,0,sizeof(p));
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(cnt,0,sizeof(cnt));
        memset(vis,0,sizeof(vis));
        memset(tt,0,sizeof(tt));
        int tot=0,temp=0,ans=0;
        for(int i=1;i<=n;i++)
            scanf("%d %d %d",&d[i],&v[i],&a[i]);
        for(int i=1;i<=m;i++)
            scanf("%d",&p[i]);
        for(int i=1;i<=n;i++)
        {   if(a[i]==0)
                if(v[i]>V)
                {   l[i]=lower_bound(p+1,p+m+1,d[i])-p;
                    r[i]=m;
                    if(l[i]<=r[i])
                        cnt[i]=r[i]-l[i]+1;
                }
            if(a[i]<0)
                if(v[i]>V)
                {   l[i]=lower_bound(p+1,p+m+1,d[i])-p;
                    r[i]=lower_bound(p+1,p+m+1,ceil((v[i]*v[i]-V*V)*1.0/(abs(a[i])*2))+d[i])-p-1;
                    r[i]=min(r[i],m);
                    if(l[i]<=r[i])
                        cnt[i]=r[i]-l[i]+1;
                }
            if(a[i]>0)
            {   if(v[i]>V)
                {   l[i]=lower_bound(p+1,p+m+1,d[i])-p;
                    r[i]=m;
                    if(l[i]<=r[i])
                        cnt[i]=r[i]-l[i]+1;
                }
                if(v[i]==V)
				{   l[i]=lower_bound(p+1,p+m+1,d[i])-p+1;
                    r[i]=m;
                    if(l[i]<=r[i])
                        cnt[i]=r[i]-l[i]+1;
                }
                if(v[i]<V)
                {   l[i]=lower_bound(p+1,p+m+1,ceil((V*V-v[i]*v[i])*1.0/(a[i]*2))+d[i])-p+1;
                    r[i]=m;
                    if(l[i]<=r[i])
                        cnt[i]=r[i]-l[i]+1;
                }
            }
            if(cnt[i])
			{   for(int j=l[i];j<=r[i];j++)
                    tt[j].push_back(i);
				tot++;
			}
        }
        for(int i=1;i<=m;i++)
			if(tt[i].size()==0)
			{	vis[i]=1;
				temp++;
			}
        int ll=0,rr=m;
        while(ll<=rr)
		{	int mid=(ll+rr)/2;
			if(judge(mid))
			{	ans=mid;
				ll=mid+1;
			}
			else
				rr=mid-1;
		}
		printf("%d %d\n",tot,ans+temp);
    }
    return 0;
}
